如果你在用Vim,如果你还没听说VundleUltiSnips或者YouCompleteMe,那么你一定不要错过这篇文章。

安装Vim 7.4

MacOS 10.9自带的Vim还是7.3的版本,不支持YouCompleteMe插件,所以需要先从官网下载解压,然后进入解压目录运行命令:

1
2
3
./configure --with-features=huge --enable-pythoninterp=yes --enable-cscope --enable-fontset --enable-perlinterp --enable-rubyinterp --with-python-config-dir=/usr/lib/python2.6/config --prefix=/opt/local
sudo make install
如果在make的过程中会出现如下错误:

:info:build os_unix.c:830:46: warning: declaration of 'struct sigaltstack' will not be visible outside of this function [-Wvisibility]
:info:build         extern int sigaltstack __ARGS((const struct sigaltstack *ss, struct sigaltstack *oss));
:info:build                                                     ^
:info:build ./os_unix.h:88:21: note: expanded from macro '__ARGS'
:info:build #  define __ARGS(x) x
:info:build                     ^
:info:build os_unix.c:830:13: error: conflicting types for 'sigaltstack'
:info:build         extern int sigaltstack __ARGS((const struct sigaltstack *ss, struct sigaltstack *oss));
:info:build                    ^
:info:build /usr/include/signal.h:89:5: note: previous declaration is here
:info:build int     sigaltstack(const stack_t * __restrict, stack_t * __restrict)  __DARWIN_ALIAS(sigaltstack);
:info:build         ^
:info:build 1 warning and 1 error generated.
:info:build make[1]: *** [objects/os_unix.o] Error 1
:info:build make[1]: *** Waiting for unfinished jobs….)

那么,需要在./src/os_unix.h中加上#include <AvailabilityMacros.h>。

然后重新sudo make install,在.bash_profile中添加一行“alias vim=’/opt/local/bin/vim’”,然后在终端中执行“source ~/.bash_profile”即可运行最新的Vim 7.4。

安装Vundle

Vundle的安装很简单:

1
git clone http://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

然后写配置文件“~/.vimrc”:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
set nocompatible " be iMproved, required
filetype off " requried
set rtp+=~/.vim/bundle/vundle/
call vundle#begin()
" let vundle manage vundle, required
Bundle 'gmarik/vundle'
" wanted plugins
Bundle 'Solarized'
Bundle 'Valloric/YouCompleteMe'
call vundle#end()
" required
filetype plugin indent on

其中,Bundle后面的内容就是插件的名字。

打开Vim之后,可以输入如下命令操作Bundle:

1
2
3
4
5
6
7
8
"安装插件:
:BundleInstall
"更新插件:
:BundleInstall!
"卸载不在列表中的插件:
:BundleClean

以下是一些常用的推荐插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#相较于Command-T等查找文件的插件,ctrlp.vim最大的好处在于没有依赖,干净利落
Bundle 'ctrlp.vim'
#在输入(),""等需要配对的符号时,自动帮你补全剩余半个
Bundle 'AutoClose'
#神级插件,ZenCoding可以让你以一种神奇而无比爽快的感觉写HTML、CSS
Bundle 'ZenCoding.vim'
#在()、""、甚至HTML标签之间快速跳转;
Bundle 'matchit.zip'
#显示行末的空格;
Bundle 'ShowTrailingWhitespace'
#JS代码格式化插件;
Bundle '_jsbeautify'
#用全新的方式在文档中高效的移动光标,革命性的突破
Bundle 'EasyMotion'
#自动识别文件编码;
Bundle 'FencView.vim'
#必不可少,在VIM的编辑窗口树状显示文件目录
Bundle 'The-NERD-tree'
#NERD出品的快速给代码加注释插件,选中,`ctrl+h`即可注释多种语言代码;
Bundle 'The-NERD-Commenter'
#解放生产力的神器,简单配置,就可以按照自己的风格快速输入大段代码。
Bundle 'UltiSnips'
#让代码更加易于纵向排版,以=或,符号对齐
Bundle 'Tabular'
#迄今位置最好的自动VIM自动补全插件了吧
Bundle 'Valloric/YouCompleteMe'
#最全的语言支持
Bundle 'sheerun/vim-polyglot'

其中,插件YouCompleteMe安装后启动Vim如果提示错误:

1
ycm_client_support.[so|pyd|dll] and ycm_core.[so|pyd|dll] not detected; you need to compile YCM before using it. Read the docs!

那么,需要手工编译出YCM库文件:

1
2
3
cd ./install.sh --clang-completer ~/.vim/bundle/YouCompleteMe
git submodule update --init --recursive
./install.sh --clang-completer

我的插件

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""""""""""""""""""""""""""""""""""""""""
" vundle
"""""""""""""""""""""""""""""""""""""""""
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle
call vundle#begin()
" let vundle manage vundle, required
Bundle 'gmarik/vundle'
" The following are plugins needed
Bundle 'L9'
Bundle 'Solarized'
Bundle 'ctrlp.vim'
Bundle 'AutoClose'
Bundle 'mattn/emmet-vim'
Bundle 'matchit.zip'
Bundle 'ShowTrailingWhitespace'
Bundle 'FencView.vim'
Bundle 'The-NERD-tree'
Bundle 'The-NERD-Commenter'
Bundle 'Tabular'
Bundle 'sheerun/vim-polyglot'
Bundle 'ervandew/supertab'
Bundle 'SirVer/ultisnips'
Bundle 'honza/vim-snippets'
Bundle 'Valloric/YouCompleteMe'
Bundle 'VimClojure'
Bundle 'tpope/vim-leiningen'
Bundle 'bling/vim-airline'
Bundle 'scrooloose/syntastic'
Bundle 'Shougo/unite.vim'
Bundle 'tpope/vim-fireplace'
Bundle 'suan/vim-instant-markdown'
call vundle#end()
filetype plugin indent on " required
" Brief help
" :PluginList
" :PluginInstall
" :PluginSearch foo
" :PluginClean
"""""""""""""""""""""""""""""""""""""""
" UltiSnips
"""""""""""""""""""""""""""""""""""""""
" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-N>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-P>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-N>'
let g:UltiSnipsExpandTrigger="<Tab>"
let g:UltiSnipsListSnippets = '<C-Tab>'
let g:UltiSnipsJumpForwardTrigger="<Tab>"
let g:UltiSnipsJumpBackwardTrigger="<S-Tab>"
""""""""""""""""""""""""""""""""""""""""
" ZenCoding
""""""""""""""""""""""""""""""""""""""""
let g:user_emmet_mode='a' "enable all function in all mode
let g:user_emmet_install_global = 0
autocmd FileType html,css EmmetInstall
let g:user_zen_expandabbr_key = '<C-Y>'
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:instant_markdown_slow = 1

留言